#pragma once
#ifndef __OGRE__CREATOR__INCLUDED__HH__
#define __OGRE__CREATOR__INCLUDED__HH__

#include <Ogre.h>

class OgreCreator
{
	Ogre::Root*				mRoot;
	Ogre::RenderWindow*		mWindow;
	Ogre::Camera*			mCamera;
	Ogre::SceneManager*		mSceneMgr;

	void setupResources( const std::string &filename )
	{
		//-------------------------------------------------------------------------------------
		// setup resources
		// Load resource paths from config file
		Ogre::ConfigFile cf;
		cf.load(filename);

		// Go through all sections & settings in the file
		Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

		Ogre::String secName, typeName, archName;
		while (seci.hasMoreElements())
		{
			secName = seci.peekNextKey();
			Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
			Ogre::ConfigFile::SettingsMultiMap::iterator i;
			for (i = settings->begin(); i != settings->end(); ++i)
			{
				typeName = i->first;
				archName = i->second;
				Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
					archName, typeName, secName);
			}
		}
	}
	bool configureRendering( )
	{
		//-------------------------------------------------------------------------------------
		// configure
		// Show the configuration dialog and initialise the system
		// You can skip this and use root.restoreConfig() to load configuration
		// settings if you were sure there are valid ones saved in ogre.cfg
		if(mRoot->restoreConfig() || mRoot->showConfigDialog())
		{
			// If returned true, user clicked OK so initialise
			// Here we choose to let the system create a default rendering window by passing 'true'
		
			mWindow = mRoot->initialise( true, "Engine Render Window");
		}
		else
		{
			return false;
		}
		return true;
	}
	void create( )
	{
		mRoot = new Ogre::Root("plugins.cfg");
		setupResources( "resources.cfg" );
		configureRendering( );
	}
};
#endif